package com.ny.controller;

import com.ny.entity.Classrooms;
import com.ny.entity.Users;
import com.ny.service.ClasssroomService;
import com.ny.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private ClasssroomService classsroomService;
    @RequestMapping("/login")
    public String login (String username, String password, Model model){
        Users users = userService.findUserByUsernameAndPassword(username,password);
        if (users!=null && users.getRole().equals("学生")){
            List<Classrooms> classroomsList = classsroomService.findAllClassrooms();
            model.addAttribute("classroomsList",classroomsList);
            return "classroom";
        }
        else {
            return "login";
        }
    }

}
